/**
 * 
 */
package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.exceptions.NotEnoughFundsException;

/**
 * @author Artem Kalchenko
 * 
 */
public class SavingsAccount extends AbstractAccount {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Create savings account with 0 balance
	 */
	public SavingsAccount() {
		super();
	}

	/**
	 * Create savings account
	 * 
	 * @param balance
	 *            - initial balance
	 */
	public SavingsAccount(double balance) {
		super(balance);
	}

	/**
	 * Withdraw the money from the checking account. If the sum is greater than
	 * the balance, overdraft is used
	 * 
	 * @param sum
	 *            - amount to withdraw. Should be non-zero
	 */
	@Override
	public void withdraw(double sum) throws NotEnoughFundsException,
			IllegalArgumentException {
		if (sum <= 0) {
			throw new IllegalArgumentException(
					"Withdraw amount should be positive");
		}
		if (this.balance < sum) {
			throw new NotEnoughFundsException();
		}
		this.balance -= sum;
	}

	/**
	 * Show the maximum amount the client can withdraw, i.e. the balance
	 */
	@Override
	public double maximumAmountToWithdraw() {
		return this.balance;
	}

	@Override
	public String toString() {
		return "ID" + this.getId() + " Savings account, balance: " + this.getBalance();
	}

}
